/* main plays sound ID # 129 until its done or a key is pressed */
void main( void);
/* Every program needs a bug, this program currently has none, as you can clearly see because DEBUG is false. I encourage you to add to this code until it has atleast three good bugs. */
#define DEBUG false
/* The KillKey is currently set to the space bar
(0x31). The list of keys can be found in InsideMac’s Vol. I pg. 251; Vol. IV pg. 250, and
Vol. VI pg. 191-2 */
#define KILLKEY 0x31
/* kSndRsrc holds the resource #, 129 is compatible with cdev’s, see Dave Mark’s “Macintosh C Programming Primer Vol. II.” See chapter 3. */
#define kSndRsrc 129
/********************* main *********************/
void main()
{
SCStatus sndStatus; // Used while snd plays
Handle theSnd; // the snd resource
OSErr playStatus; // standard error var
KeyMap theKeys; // bit map of key presses
// the channel through which sound will come
SndChannelPtr theChannel;
/* If there are any bugs, then go to the debugger first. */
#if DEBUG
Debugger();
#endif
/* Check to see if the KillKey is pressed */
GetKeys( &theKeys); // Read the keyboard
if(KeyPressed(KILLKEY,
(unsigned char*)theKeys) == false)
{ // if the space bar is not pressed, continue
/* Set the channel ptr to NIL */
theChannel = (SndChannelPtr) 0l;
/* Allocate a new channel */
playStatus = SndNewChannel( &theChannel, 0,
(long int)0, (SndCallBackProcPtr) 0);
/* As long as that worked fine... */
if( playStatus == noErr)
{
/* Read the sound resource into memory */
theSnd = GetResource('snd ', kSndRsrc);
/* 0 is returned if there was a res error */
if( theSnd)
{
/* SoundPlay needs the channel, the sound, */
playStatus = SndPlay( theChannel, theSnd, true); // and an ASYNC flag